<template>
  <div class="user-member-dialog">
    <el-dialog
      v-model="dialogVisible"
      width="550"
      :modal="false"
      align-center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :destroy-on-close="true"
      @closed="closedHandle"
    >
      <div class="content">
        <div class="content-title">
          下载提示
        </div>
        <div class="content-paragraph">
          <span class="content-paragraph1">您的会员已失效，下载任务暂停。立即续费会员，继续享受极速下载特权！</span>
        </div>
        <div class="user-member-table">
          <div
            v-for="item in tableList"
            :key="item.key"
            class="user-member-table-row"
          >
            <div
              v-for="item1 in item.list"
              :key="item1.title"
              :class="`user-member-table-cell ${item1.bgColor?'bg-color':''} ${item1.borderClass||''}`"
              :style="`background:${item1.background};color:${item1.color}`"
            >
              {{ item1.title }}
            </div>
          </div>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            type="default"
            class="button"
            @click="handleSuccessInner"
          >
            <span>普通下载</span>
          </el-button>
          <el-button
            type="primary"
            class="button"
            @click="handleCancelInner('member')"
          >
            极速下载
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { storeToRefs } from 'pinia'

const props = defineProps({
  handleSuccess: {
    type: Function,
    default:()=>{}
  },
  handleCancel: {
    type: Function,
    default:()=>{}
  }
})

const dialogVisible = ref(true)
const clickType = ref('cancel')
const cancelType = ref('cancel')

type tableListItemType = {
  title?: string;
  background?: string;
  bgColor?: boolean;
  color?: string;
  border?: string;
  borderClass?: string;
}

type tableListType = {
  key: string;
  list:tableListItemType[]
}

const tableList:tableListType[] = [
  {
    key: '1',
    list: [
      {
        title: '功能',
        background: 'rgba(74,141,255,0.1)',
        bgColor: true,
        color: '#1D4563',
      },
      {
        title: '普通用户',
        background: 'rgba(57,66,110,0.1)',
        bgColor: true,
        color: '#1D4563',
      },
      {
        title: '高级会员',
        background: 'linear-gradient( 180deg, #FFE5B4 0%, #FFD583 100%)',
        bgColor: true,
        color: '#7B4801',
      }
    ]
  },
  {
    key: '2',
    list: [
      {
        title: '下载速度',
        border: '1px solid rgba(57,66,110,0.1)',
        borderClass: 'four-rect',
        color: '#1D4563',
      },
      {
        title: '一般',
        borderClass: 'four-rect-top-bottom',
        color: '#1D4563',
      },
      {
        title: '极速下载',
        borderClass: 'four-rect',
        color: '#7B4801',
      }
    ]
  },
  {
    key: '3',
    list: [
      {
        title: '纯净无广告',
        borderClass:'four-rect-left-right',
        color: '#1D4563',
      },
      {
        title: '有',
        color: '#1D4563',
      },
      {
        title: '无',
        borderClass: 'four-rect-left-right',
        color: '#7B4801',
      }
    ]
  },
  {
    key: '4',
    list: [
      {
        title: 'VIP专属客服',
        borderClass: 'four-round-left',
        color: '#1D4563',
      },
      {
        title: '无',
        borderClass: 'four-rect-top-bottom',
        color: '#1D4563',
      },
      {
        title: '一对一专属客服',
        borderClass: 'four-round-right',
        color: '#7B4801',
      }
    ]
  }
]

const handleSuccessInner = () => {
  clickType.value = 'success'
  dialogVisible.value = false
}

const handleCancelInner = (_cancelType: string) => {
  clickType.value = 'cancel'
  cancelType.value = _cancelType
  dialogVisible.value = false
}

const closedHandle = () => {
  if (clickType.value === 'success') {
    props.handleSuccess()
  } else {
    props.handleCancel(cancelType.value)
  }
}
</script>

<style scoped lang="scss">
.user-member-dialog {
  :deep(.el-dialog){
    background:#fff url('@/assets/svg/user-member-bg.svg') no-repeat center top/contain;
  }
  
  .content-title{
    text-align:center;
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: bold;
    font-size: 16px;
    color: #192655;
  }
  .content-paragraph{
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-size: 14px;
    margin:17px 0;
    text-align: center;
    .content-paragraph1{
      font-weight: 400;
      color: #192655;
    }
    .content-paragraph2{
      margin-left: 10px;
      font-weight: bold;
      color: #7B4801;
    }
  }
  .user-member-table{
    .user-member-table-row{
      display: flex;
      .user-member-table-cell{
        width:33%;
        text-align: center;
        height:34px;
        line-height: 34px;
        box-sizing: border-box;
        &.bg-color{
          border-radius: 10px 10px 0px 0px;
        }
        &.four-rect,&.four-round-left,&.four-round-right,&.four-rect-top-bottom,&.four-rect-left-right{
          border:1px solid  rgba(57,66,110,0.1);
        }
        &.four-round-left{
          border-radius: 0 0 0 10px;
        }
        &.four-round-right{
          border-radius: 0 0 10px 0;
        }
        &.four-rect-top-bottom{
          border-left: none;
          border-right: none;
        }
        &.four-rect-left-right{
          border-top:none;
          border-bottom: none;
        }
      }
    }
  }
  
  .dialog-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    margin:10px 0;
    gap:20px;
    button{
      width:190px;
      height:42px;
      border-radius: 20px;
    }
  }
}
</style>
